package com.generic.handler.impl;

import java.io.File;

import com.generic.dao.impl.ImageDao;
import com.generic.ds.HibernateSession;
import com.generic.handler.ModuleHandler;
import com.generic.module.impl.Image;

public class ImageHandler extends ModuleHandler {

	public ImageHandler(HibernateSession session) {
		super(new ImageDao(session));
	}
	
	public void add(Long profileId, String filePath, File[] files, String[] fileNames) {
		for (int i = 0; i < files.length; i++) {
			File file = new File(filePath, fileNames[i]);
			if (!file.exists()) {
				files[i].renameTo(file);
				Image image = new Image();
				image.setProfileId(profileId);
				image.setImagePath(filePath);
				dao.insertOrUpdate(image);
			}
		}
	}
}
